# Created by 黄景涛
# DATE: 2025/3/6
import json

import requests
import yaml
from transfer import get_new_data

headers = {
    "Cookie": "esmv35_saas_csrftoken=MYGMyCqW2JN9HwTjMtqalAnGTdxCtFJWbWvp1VcyE7FBA0n77gC4uBv4N2qvuPhJ; "
               "esmv35_saas_sessionid=cf3s7o29c643q3estntqajhm4ep3qkoc; "
               "bk_csrftoken=KZZFiI4ct4nJoAb5UDmLU4CPahb9ntsIHmoDaSmssXung0Xmn7h0y4pudiqepaWg; recently_portal_id=1; "
               "bkuser_csrftoken=jluOPA0rOpPxCOOF7vEJBWG0rVnUWeDNaZPSoWLvv9aJmwwHVeqlbngewyROVfSS; "
               "o_s=%7B%22lock%22%3Atrue%2C%22msg%22%3A%7B%7D%7D; o_f=%7B%22lock%22%3Afalse%2C%22msg%22%3A%7B%7D%7D; "
               "bkitsm_csrftoken=IsO1yVZlHLo3o0etSRSHq98W9nIo5fQlFg7nsNosUMawcCI3H94PQbj7BFCKjdig; "
               "_sessionid=1l3esl1b34wjau2wihv5eqw9hrdcm4z2; blueking_language=zh-cn; "
               "sessionid=0ecl5djjdun632a0nudymeyp4z3gbnte; bk_token=qnxCtNtcC3H92dB6ynweUUVJacxXRNEmGFV5wOMCVpw; "
               "bklogin_csrftoken=1uNVtSJGxU5JsxXYxy4JpkwVh15s0WbHm6AVcahHreWqKLr4phpZyyL1dxFxSPHV",
    "Portal": "DEFAULT",
}


def add_data_dict(data: dict):
    url = "http://paas.test.com/o/esmv40_feature_saas/core/api/v2/data_source/data_dictionary/"
    response = requests.post(url, json=data, headers=headers, verify=False)
    assert response.status_code in (200, 201), f"请求失败，状态码：{response.status_code}"
    assert response.json().get('message') == "success", f"请求失败，响应信息：{response.text[:50]}"


if __name__ == '__main__':
    get_new_data('cascade_data.yaml')
    with open('new_data.json', 'r', encoding='utf8') as f:
        data = json.load(f)
    print(data)

    add_data_dict(data)


